package com.yicong.ants.view;

import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.yicong.ants.R;

/**
 * 确认提示框
 */
public class ConfirmPopupWindow extends BasePopupWindow {

    private TextView mTvTitle;
    private TextView mTvContext;
    private TextView mTvConfirm;
    private TextView mTvCancel;
    private ConfirmPopCall mCall;
    public ConfirmPopupWindow(Context context) {
        super(context);
        setAnimationStyle(android.R.style.Animation_Dialog);
    }

    @Override
    public void initListener() {
        mTvCancel.setOnClickListener(v -> dismiss());
        mTvConfirm.setOnClickListener(v -> {
            if (null != mCall) {
                mCall.onClick();
                dismiss();
            }
        });
    }

    public void setCall(ConfirmPopCall mCall) {
        this.mCall = mCall;
    }

    public void setTxtTitle(String sb) {
        if (!TextUtils.isEmpty(sb) && null != mTvTitle) {
            mTvTitle.setText(sb);
        }
    }

    public void setTxtContent(String sb) {
        if (!TextUtils.isEmpty(sb) && null != mTvContext) {
            mTvContext.setText(sb);
        }
    }

    @Override
    public void initSetting() {
        this.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        this.setHeight(WindowManager.LayoutParams.MATCH_PARENT);
    }

    @Override
    public void initView() {
        mView = LayoutInflater.from(mContext).inflate(R.layout.popup_window_confirm, null);
        mTvTitle = mView.findViewById(R.id.tv_title);
        mTvContext = mView.findViewById(R.id.tv_content);
        mTvConfirm = mView.findViewById(R.id.tv_confirm);
        mTvCancel = mView.findViewById(R.id.tv_cancel);
    }

    public interface ConfirmPopCall {
        void onClick();
    }
}
